package etm.servlet.residente;

import java.io.IOException;
import java.sql.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import etm.excepcion.DAOExcepcion;
import etm.negocio.GestionQueja;
import etm.negocio.GestionResidente;

/**
 * Servlet implementation class ResidenteInsertaServlet
 */
@WebServlet("/ResidenteInsertaServlet")
public class ResidenteInsertaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ResidenteInsertaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("Dentro de doPost del servlet ResidenteInsertaServlet");
		
		
		GestionResidente negocio = new GestionResidente();
		try {
			String fecha = request.getParameter("txfecnac");
			Date datFecNac = Date.valueOf(fecha);
			String strDocumento = request.getParameter("txdocumento");
			String strApPaterno = request.getParameter("txappaterno");
			String strApMaterno = request.getParameter("txapmaterno");
			String strNombres = request.getParameter("txnombres");
			String strEmail = request.getParameter("txemail");
			String strClave = request.getParameter("txclave");
			
			
			negocio.insertar(strDocumento,strApPaterno,strApMaterno, strNombres,datFecNac, strEmail, strClave);
			response.sendRedirect(request.getContextPath()	+ "/ResidenteBuscaServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
